#include <QtGui>
#include <QPalette>
#include <QColor>
#include <QVBoxLayout>
#include<QPixmap>
#include "radioclock.h"
#include "digitalclock.h"

RadioClock::RadioClock(QWidget *parent): QWidget(parent)
{
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    timer->start(1000);

    this->setObjectName(tr("RADIO CLOCK"));

    DigitalClock *clockinside = new DigitalClock(this,5);
    //    clockinside->setFixedHeight(this->height()/3);
    //    int width = ((parent->width()) / 2) - 25;
    //    int height = ((parent->height()) / 2) - 25;
    clockinside->move(QPoint(50,50));

    //    resize(350,350);
}

void RadioClock::paintEvent(QPaintEvent *)
{
    int side = qMin(width(), height());
    QTime time = QTime::currentTime();

    QPainter painter(this);

    QColor hourColor(127, 0, 127);
    QColor secondColor(0,0,0);

    QPalette p(palette());
    p.setColor(QPalette::Background, Qt::black);
    this->setAutoFillBackground(true);
    this->setPalette(p);

    painter.setRenderHint(QPainter::Antialiasing);
    painter.translate(width() / 2, height() / 2);
    painter.scale(side / 200.0, side / 200.0);

    painter.setPen(Qt::NoPen);
    painter.setBrush(hourColor);

    painter.setPen(hourColor);

    for (int i = 0; i < 12; ++i) {
        painter.drawLine(0, 90, 0, 95);
        painter.rotate(30.0);
    }

    painter.setPen(Qt::NoPen);
    painter.setBrush(secondColor);

    painter.setPen(secondColor);
    for (int j = 0; j <= time.second(); ++j) {
        QPen pointPen(Qt::black, 1);
        painter.setPen(pointPen);
        QColor* pointColor = new QColor(255,140,10);
        QBrush brush(*pointColor);
        painter.setBrush(brush);
        painter.drawEllipse(-3, -85, 6, 6);
        painter.rotate(6.0);
    }
}
